#include <napi_call.h>
#include <node_api.h>

struct PropData {
    napi_value val = nullptr;
    const char *utf8name = "unknown";
};
PropData props[] = {
    {.utf8name = "int32"},
    {.utf8name = "uint32"},
    {.utf8name = "int64"},
    {.utf8name = "double"},
    {.utf8name = "bigint_int64"},
    {.utf8name = "bigint_uint64"},
    {.utf8name = "bigint_words"},
    {.utf8name = "string_latin1"},
    {.utf8name = "string_utf16"},
    {.utf8name = "string_utf8"},
    {.utf8name = "boolean"},
};

/* napi_value */
NAPI_MODULE_INIT(/* napi_env env, napi_value exports */)
{
    int index = 0;

    NAPI_CALL(env, napi_create_int32(env, -1234, &props[index++].val)); // 0: number -1234
    NAPI_CALL(env, napi_create_uint32(env, 1234, &props[index++].val)); // 1: number 1234
    NAPI_CALL(env, napi_create_int64(env, 1e18, &props[index++].val)); // 2: number 1000000000000000000
    NAPI_CALL(env, napi_create_double(env, 1e25, &props[index++].val)); // 3: number 1e+25
    NAPI_CALL(env, napi_create_bigint_int64(env, -164, &props[index++].val)); // 4: bigint -164
    NAPI_CALL(env, napi_create_bigint_uint64(env, 164, &props[index++].val)); // 5: bigint 164

    uint64_t words[] = {0xffffffffffffffffLL, 0xffffffffffffffffLL};
    NAPI_CALL(env, napi_create_bigint_words(env, 0, sizeof(words) / sizeof(*words), words, &props[index++].val));
        // 6: bigint 340282366920938463463374607431768211455

    NAPI_CALL(env, napi_create_string_latin1(env, "latin1", NAPI_AUTO_LENGTH, &props[index++].val)); // 7: string latin1
    NAPI_CALL(env, napi_create_string_utf16(env, u"utf16", NAPI_AUTO_LENGTH, &props[index++].val)); // 8: string utf16
    NAPI_CALL(env, napi_create_string_utf8(env, "utf8", NAPI_AUTO_LENGTH, &props[index++].val)); // 9: string utf8
    NAPI_CALL(env, napi_get_boolean(env, true, &props[index++].val)); // 10: boolean true

    for (auto &prop : props) {
        NAPI_CALL(env, napi_set_named_property(env, exports, prop.utf8name, prop.val));
    }
    return exports;
}
